//
//  HMVisitorView.swift
//  WeiBo
//
//  Created by 李立达 on 15/12/6.
//  Copyright © 2015年 heima11. All rights reserved.
//

import UIKit

import SnapKit

class HMVisitorView: UIView {

 
   override init(frame: CGRect) {
        
        super.init(frame: frame)
    
        setupView()
    }

   required init?(coder aDecoder: NSCoder) {
       fatalError("init(coder:) has not been implemented")
   }
    
    func isdisplayView (image : UIImage?, messagelable : String? ){
    
        if let img = image, meg = messagelable {
        
            circleView.hidden = true
            centerimage.image = img
            MessageLable.text = messagelable
            
        }else
        {
            startAnim()
        }
        
    }
    
    private func startAnim() {
    
    let anim = CABasicAnimation (keyPath: "transform.rotation")
    anim.toValue = M_PI * 2
    
    anim.duration = 10
    
    anim.repeatCount = MAXFLOAT
    
    anim.removedOnCompletion = false
    
    circleView.layer.addAnimation(anim, forKey: nil)
    }
    
   private func setupView() {
    
        backgroundColor = UIColor(white: 237 / 255 , alpha: 1)
        addSubview(circleView)
        addSubview(makeIconView)
        addSubview(centerimage)
        addSubview(MessageLable)
        addSubview(reginenor)
        addSubview(loginButton)
        
        centerimage.snp_makeConstraints { (make) -> Void in
           make.center.equalTo(self.snp_center)
        }
        circleView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(centerimage.snp_center)
        }
        
        MessageLable.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(circleView.snp_bottom)
            make.centerX.equalTo(circleView)
            make.width.equalTo(224)
        }
        
        reginenor.snp_makeConstraints { (make) -> Void in
            
            make.leading.equalTo(MessageLable.snp_leading)
            make.width.equalTo(100)
            make.top.equalTo(MessageLable.snp_bottom).offset(15)
        }
        
        loginButton.snp_makeConstraints { (make) -> Void in
            
            make.trailing.equalTo(MessageLable.snp_trailing)
            make.width.equalTo(100)
            
            make.top.equalTo(MessageLable.snp_bottom).offset(15)
        }
        
        makeIconView.snp_makeConstraints { (make) -> Void in
            
            make.bottom.equalTo(reginenor)
            make.width.equalTo(self)
            make.top.equalTo(self)
        }
    }
    
    lazy var centerimage : UIImageView = {
        let image = UIImage(named: "visitordiscover_feed_image_house")
    
        let imageView = UIImageView(image: image)
        return imageView
    }()
    lazy var circleView : UIImageView = UIImageView (image: UIImage(named: "visitordiscover_feed_image_smallicon"))
    
    lazy var MessageLable : UILabel = {
        let label = UILabel()
        
        label.numberOfLines = 0
        label.text = "关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜"
        
        label.font = UIFont.systemFontOfSize(14)
        
        return label
    }()
    
    lazy var loginButton : UIButton = {
    
        let button = UIButton()
        
        button.setTitle("登录", forState: UIControlState.Normal)
        
        button.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: .Normal)
        
        return button
    }()
    
    lazy var reginenor :UIButton = {
    
        let button = UIButton()
        
        button.setTitle("注册", forState: UIControlState.Normal)
        
        button.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: .Normal)
    
        return button
    }()
    
    lazy var makeIconView : UIImageView = {
    
            let image = UIImage(named: "visitordiscover_feed_mask_smallicon")
        
        let imageview = UIImageView(image: image)
        
        return imageview
    }()
    
}
